﻿package frEngine.render
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import baseEngine.system.*;
    import flash.geom.*;
    import frEngine.primitives.*;

    public class FrPlaneRender extends DefaultRender
    {
        private var _tempVect3d:Vector3D;
        private var _right:Vector3D;
        private var _up:Vector3D;
        private var _dir:Vector3D;
        private var _pos:Vector3D;
        private var _scale:Vector3D;
        public static const instance:FrPlaneRender = new FrPlaneRender;

        public function FrPlaneRender()
        {
            this._tempVect3d = new Vector3D();
            this._right = new Vector3D();
            this._up = new Vector3D();
            this._dir = new Vector3D();
            return;
        }// end function

        override protected function calculateObjectWorld(param1:Mesh3D) : void
        {
            var _loc_4:Vector.<Vector3D> = null;
            var _loc_5:Vector3D = null;
            var _loc_2:* = FrPlane(param1);
            var _loc_3:* = _loc_2.world;
            if (_loc_2.faceCamera)
            {
                _loc_4 = _loc_3.decompose(Orientation3D.EULER_ANGLES);
                this._pos = _loc_4[0];
                this._pos.w = 1;
                this._scale = _loc_4[2];
                _loc_5 = _loc_2.faceCameraAxis;
                if (_loc_5 != null)
                {
                    this._up.x = _loc_5.x;
                    this._up.y = _loc_5.y;
                    this._up.z = _loc_5.z;
                    this._right = Global3D.cameraForward.crossProduct(this._up);
                    this._right.normalize();
                    this._dir = this._up.crossProduct(this._right);
                    this._right.scaleBy(this._scale.x);
                    this._up.scaleBy(this._scale.y);
                    this._dir.scaleBy(this._scale.z);
                    var _loc_6:int = 0;
                    this._dir.w = 0;
                    var _loc_6:* = _loc_6;
                    this._up.w = _loc_6;
                    this._right.w = _loc_6;
                    _matrix3d.copyColumnFrom(0, this._right);
                    _matrix3d.copyColumnFrom(1, this._up);
                    _matrix3d.copyColumnFrom(2, this._dir);
                    _matrix3d.copyColumnFrom(3, this._pos);
                }
                else
                {
                    _matrix3d.copyFrom(Device3D.faceCameraMatrix3d);
                    _matrix3d.prependScale(this._scale.x, this._scale.y, this._scale.z);
                    _matrix3d.position = this._pos;
                }
            }
            else
            {
                _matrix3d.copyFrom(_loc_3);
            }
            _matrix3d.prepend(_loc_2.offsetMatrix);
            return;
        }// end function

    }
}
